﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using ZombZomb.GameObjects;

namespace ProjetPlatformer.gameElements
{
    class Hero2 : ControlableGameElement
    {


        public Hero2(Game game, SpriteBatch sb, ContentManager cm) : base(game,sb,cm)
        {
            image = cm.Load<Texture2D>("perso30x53");
            this.bBox.Width = 30;
            this.bBox.Height = 53;
            sprite.IsSpriteSheet = true;
            sprite.Image = image;
            sprite.Position = this.position;
            sprite.AddAnimation("marche",0,0,30,53,7,0.1f);
            sprite.CurrentAnimation = "marche";
            sprite.Scale = 2f;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            sprite.Update(gameTime, this.position, 0f, moving);
            //logique du sprite
            if (moving && !jumping)
            {
                if (!sprite.CurrentAnimation.Contains("marche"))
                {
                    sprite.CurrentAnimation="marche";
                }

                sprite.IsAnimating = true;
                
            }
            else
            {
                sprite.IsAnimating = false;
                sprite.CurrentFrameAnimation.CurrentFrame = 0;
            }
            if (jumping)
            {
                /*if (!sprite.CurrentAnimation.Contains("saut"))
                {
                    sprite.CurrentAnimation = "saut";
                }*/
                sprite.IsAnimating = true;
            }
            else
            {
                if (!sprite.CurrentAnimation.Contains("marche"))
                {
                    sprite.CurrentAnimation = "marche";
                    sprite.IsAnimating = false;
                    sprite.CurrentFrameAnimation.CurrentFrame = 0;
                }
            }
            if (protecting)
            {
                /*if (!sprite.CurrentAnimation.Contains("bas"))
                {
                    sprite.CurrentAnimation = "bas";
                }*/
                sprite.IsAnimating = true;
            }
            
        }

        public override void Draw(GameTime gameTime)
        {
            
            sprite.Draw(spriteBatch);
        }

    }
}
